
a = int(input())
c1 = 0 
c2 = 0 
c3 = 0 
c4 = 0 
cif = 0 
pov = 1
bol1 = 0 
pr = 0
kl = 0
prosoi = []
chisla = []
if a > 1000 and a < 10000:
    while a != 0:
        cif = a % 10 
        if pov == 1:
            c4 = cif
        if pov == 2:
            c3 = cif
        if pov == 3:
            c2 = cif
        if pov == 4:
            c1 = cif
        pov += 1 
        a = a // 10
    c11 = str(c1)
    c22 = str(c2)
    c33 = str(c3)
    c44 = str(c4)
    c12 = c11 + c22
    chisla.append(int(c12))              
    c13 = c11 + c33
    chisla.append(int(c13))
    c14 = c11 + c44
    chisla.append(int(c14))      
    c123 = c11 + c22 + c33
    chisla.append(int(c123))
    c134 = c11 + c33 + c44
    chisla.append(int(c134))
    c124 = c11 + c22 + c44
    chisla.append(int(c124))   
    c23 = c22 + c33
    chisla.append(int(c23))
    c24 = c22 + c44
    chisla.append(int(c24))
    c234 = c22 + c33 + c44
    chisla.append(int(c234)) 
    c34 = c33 + c44
    chisla.append(int(c34))     
    chisla.append(int(c1))     
    chisla.append(int(c2))         
    chisla.append(int(c3))            
    chisla.append(int(c4))
    c1234 = c11 + c22 + c33 + c44
    chisla.append(int(c1234))
    for i in chisla:
        pr = 0
        for j in range(1, i + 1):
            if i % j == 0:
                pr += 1
        if pr == 2:
            prosoi.append(i)
            kl += 1
    if kl == 0:
        print('0')
    else:
        prosoi.sort()
        print(prosoi[-1])
else:
    print('0')

